<extend name="Common@Layout:hui-admin" />
<block name="title"><title>Administator管理后台</title></block>
<block name="style">
<css href="/Public/Static/bootstrap3-editable/css/bootstrap-editable.css"/>
</block>

<block name="main">
	<nav class="breadcrumb">
		<i class="Hui-iconfont"></i>
		 首页 <span class="c-gray en">&gt;</span>
		 内容管理 <span class="c-gray en">&gt;</span>  
		表格可编辑 资讯列表 
		<a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a>
	</nav>
	
	<div class="pd-20">
		<div class="cl pd-5 bg-1 bk-gray mt-20"> 
			<div class="btn-group l">
				<a href="{:U('Datagridadmin/demo',array(status=>0))}" class="btn btn-default <if condition='$_GET["status"] eq 0'>btn-primary</if> radius">全部</a>
			  	<a href="{:U('Datagridadmin/demo',array(status=>1))}" class="btn btn-default <if condition='$_GET["status"] eq 1'>btn-primary</if> radius">发布</a>
			  	<a href="{:U('Datagridadmin/demo',array(status=>2))}" class="btn btn-default <if condition='$_GET["status"] eq 2'>btn-primary</if> radius">草稿</a>
			</div>
			<span class="l ml-20"> 
				<a href="javascript:;" class="btn btn-danger radius ajax-post confirm" target-form="mini-form" data-msg="确定批量删除？" data-url="{:U('Articles/del')}"><i class="Hui-iconfont"></i> 批量删除</a> 
				<a class="btn btn-primary radius" href="javascript:;" onclick="open_iframe_dialog('{:U('articles/edit')}','创建文章',['100%','100%'],1)"><i class="Hui-iconfont"></i> 添加文章</a> 
			</span> 
		</div>
		<php>
			$result = _get_list_data(U('Datagridadmin/index'),$_GET,$map,D('Datagrid'));
		</php>
		<form class="mini-form">
		<table id="datagrid" class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="80">ID</th>
					<th>data1</th>
					<th>data2</th>
					<th>data3</th>
					<th>data4</th>
					<th>data5</th>
					<th width="120">更新时间</th>
					<th width="60">发布状态</th>
					<th width="120">操作</th>
				</tr>
			</thead>
			<tbody>
				<foreach name="result['data']['list']" item="vo">
				<tr class="text-c" data-trid="{$vo.id}">
					<td><input type="checkbox" value="{$vo['id']}" name="ids[]"></td>
					<td>{$vo.id}</td>
					<td><a class="data1"  href="#" data-name="data1" data-type="text" data-pk="{$vo.id}" data-inputclass="input-text" data-url="/Material/Datagridadmin/savedatabyenter" data-title="Enter data">{$vo.data1}</a></td>
					<td><a class="data2"  href="#" data-name="data2" data-type="textarea" data-pk="{$vo.id}" data-inputclass="textarea" data-url="/Material/Datagridadmin/savedatabyenter" data-title="Enter data">{$vo.data2}</a></td>
					<td><a class="data3"  href="#" data-name="data3" data-type="select" data-pk="{$vo.id}" data-inputclass="input-text"  data-value="{$vo.data3}" data-url="/Material/Datagridadmin/savedatabyenter" data-title="Enter data">{$vo.data3}</a></td>
					<td>{$vo.data4}</td>
					<td>{$vo.data5}</td>
					<td>{$vo.create_time}</td>
					<td class="td-status">
						<if condition="$vo['status'] eq 1">
						<span class="label label-success radius">已发布</span>
						</if>
						<if condition="$vo['status'] eq 2">
						<span class="label label-default radius">草稿</span>
						</if>
					</td>
					<td class="f-14 td-manage">
						<if condition="$vo['status'] eq 1">
						<a style="text-decoration:none" class="ml-5 ajax-get shuaxin" data-url="{:U('Datagridadmin/changestatus','id='.$vo['id'].'&status=2')}" href="javascript:;" title="下架"><i class="Hui-iconfont"></i></a>
						</if>
						<if condition="$vo['status'] eq 2">
						<a style="text-decoration:none" class="ml-5 ajax-get shuaxin" data-url="{:U('Datagridadmin/changestatus','id='.$vo['id'].'&status=1')}" href="javascript:;" title="发布"><i class="Hui-iconfont"></i></a>
						</if>
            			<a style="text-decoration:none" class="ml-5 mini_del" data-url="{:U('Datagridadmin/del','ids='.$vo['id'])}" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a>
					</td>
				</tr>
				</foreach>
			</tbody>
		</table>
		</form>
		{$result['pagetpl']}
	</div>
	
	
</block>

<block name="script">
<js href="/Public/Static/bootstrap3-editable/js/bootstrap-editable.min.js"/>
<script>
$(function(){
	$.fn.editable.defaults.mode = 'inline';
	$.fn.editableform.buttons = '<button type="submit" class="btn btn-primary btn-sm editable-submit"><i class="Hui-iconfont Hui-iconfont-edit"></i></button><button type="button" class="btn btn-default btn-sm editable-cancel"><i class="Hui-iconfont Hui-iconfont-close"></i></button>';
	 $(".data1").editable({showbuttons: false});
	 $(".data2").editable();
	 $(".data3").editable({   
        source: [
              {value: 1, text: '1'},
              {value: 2, text: '2'},
              {value: 3, text: '3'}
           ],
        showbuttons: false,
        display: function(value, sourceData) {
        	  elem = $.grep(sourceData, function(o){return o.value == value;});
        	  if(elem.length) {    
                  $(this).text(elem[0].text); 
              } else {
                  $(this).empty(); 
              }
        	}
	 });
})

</script>
</block>